package com.example.demo.repository;

import com.example.demo.entity.SeataAccount;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;


/**
 * @author zxk
 */
public interface AccountRepository extends JpaRepository<SeataAccount, Integer> {

    @Transactional(rollbackFor = Exception.class)
    @Modifying
    @Query("update SeataAccount set money=money-:money where userId=:userId and money-:money>=0")
    Integer debit(@Param("userId")Integer userId,@Param("money") BigDecimal money);
}
